
import time
from appium import webdriver
from common.log import logger
from common.readConfig import ReadConfig


class Driver:
    deviceName = None
    port = None
    def __init__(self):
        rc=ReadConfig()

        # 启动参数
        self.desire_caps = {
            "deviceName": self.deviceName,
            "platformName": rc.get_option("myapp","platformName"),
            "platformVersion": rc.get_option("myapp","platformVersion"),
            "appPackage": rc.get_option("myapp","appPackage"),
            "appActivity": rc.get_option("myapp","appActivity"),
            "noReset": bool(rc.get_option("myapp","noReset")),
            "unicodeKeyboard": bool(rc.get_option("myapp","unicodeKeyboard")),
            "autoLanuch":False
        }

    def startUp(self):
        logger.info('准备启动')

        # 启动目标设备和app
        driver = webdriver.Remote("http://127.0.0.1:"+str(self.port)+"/wd/hub", self.desire_caps)
        logger.info('启动成功，等待 6s 关闭')
        time.sleep(6)

        return driver




